import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

/**
 * File: AccountHolderTest.java
 * 
 * @author Zhiqiang Zhu Test program for class AccountHolder Enter a balance and
 *         use it to construct an new AccountHolder object. Ask the user to
 *         deposit and withdraw once and then calculate the balance using the
 *         annual interest rate and display it.
 */
public class AccountHolderTest {

	public static void main(String[] args) {
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(10);
		q.add(9);
		q.add(8);
		q.add(7);
		q.add(6);
		q.add(5);
		q.add(4);
		q.add(3);
		q.add(2);
		q.add(1);
		Queue<Integer> q2 = interChanger(q);
		// testMain(args);
	}

	public static Queue<Integer> interChanger(Queue<Integer> q) {
		Stack<Integer> st = new Stack<Integer>();
		int size = q.size() / 2;
		for (int i = 1; i <= size; i++) {
			st.push(q.remove());
		}
		System.out.println(q);

		while (!st.isEmpty()) {
			q.add(st.pop());
		}
		System.out.println(q);

		for (int i = 1; i <= size; i++) {
			q.add(q.remove());
		}
		System.out.println(q);

		for (int i = 1; i <= size; i++) {
			st.push(q.remove());
		}
		System.out.println(q);

		while (!st.isEmpty()) {
			q.add(st.pop());
			q.add(q.remove());
		}
		System.out.println(q);
		return q;
	}

	public static void testMain(String[] args) {
		// Request user to enter initial balance
		Scanner sc = new Scanner(System.in);

		// a double variable used to store user input
		double amount = 0;

		amount = enterAmout("Please enter your initial balance:");
		// Create account and set initial balance
		AccountHolder ah001 = new AccountHolder(amount);

		// Set interest rate
		AccountHolder.annualInterestRate = 0.04;
		System.out.printf("The current annual interest rate is:%.2f%%\n", AccountHolder.annualInterestRate);

		// Show menu
		int choice = 0;
		do {
			System.out.println();
			System.out.println("Please enter your choice:");
			System.out.println("1 - Deposit");
			System.out.println("2 - Withdraw");
			System.out.println("3 - Print balance");
			System.out.println("0 - Exit");

			// Check the input content until it is a menu number
			while (sc.hasNext()) {
				if (sc.hasNextInt()) {
					choice = sc.nextInt();
					// If the input character is correct, jump out of the loop
					if (choice >= 0 && choice <= 3) {
						break;
					} else {
						System.out.println("Must enter 1, 2, 3 or 0: " + choice);
					}
				} else {
					System.out.println("Must enter 1, 2, 3 or 0: " + sc.next());
				}
				System.out.print("Please re-enter your choice:");
			}

			// Perform different operations based on selection
			switch (choice) {
			case 1: {
				// Get a deposit
				amount = enterAmout("Please enter a deposit:");

				ah001.deposit(amount);
				break;
			}
			case 2: {
				// Get a withdraw
				amount = enterAmout("Please enter a withdraw:");

				if (!ah001.withdraw(amount)) {
					System.out.println("You can't withdraw this amount because the balance cannot go below $50.");
				}
				break;
			}
			case 3: {
				// Update monthly Interest to balance
				ah001.monthlyInterest();

				System.out.println();
				System.out.printf("Current balance = $%.2f", ah001.getBalance());
				System.out.println();
				break;
			}
			} // switch
		} while (choice > 0);
		System.out.println("Good bye!");

	}

	/**
	 * function enterAmount Ask the user to enter an amount, and check whether the
	 * amount is legal, until the correct value is entered, and return it
	 * 
	 * @param prompt Prompt information displayed to users
	 * @return The amount value entered by the user
	 */
	public static double enterAmout(String prompt) {
		Scanner sc = new Scanner(System.in);
		double amount = 0;
		do {
			// display prompt
			System.out.print(prompt);

			// Check the input content until it is a floating point number
			while (sc.hasNext()) {

				if (sc.hasNextDouble()) {
					amount = sc.nextDouble();
					break;
				} else {
					System.out.println("The input is not a number:" + sc.next());
					System.out.print("Please re-enter your initial balance:");
				}
			}

			// Check if it is negative
			if (amount < 0) {
				System.out.println("Only positive values are allowed.");
			}
		} while (amount < 0);

		// return entered amount
		return amount;
	}
}
